package com.huangyi.ack.config;

import com.huangyi.ack.constants.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig {
    @Bean("ackQueueAuto")
    public Queue ackQueueAuto() {
        return QueueBuilder.durable(Constants.AKC_QUEUE_AUTO).build();
    }
    @Bean("ackExchangeAuto")
    public DirectExchange ackExchangeAuto() {
        return ExchangeBuilder.directExchange(Constants.AKC_EXCHANGE_AUTO).durable(true).build();
    }
    @Bean("ackBindingAuto")
    public Binding ackBindingAuto(@Qualifier("ackQueueAuto") Queue ackQueue, @Qualifier("ackExchangeAuto") DirectExchange ackExchange) {
        return BindingBuilder.bind(ackQueue).to(ackExchange).with("abc");
    }

    @Bean("ackQueueNone")
    public Queue ackQueueNone() {
        return QueueBuilder.durable(Constants.AKC_QUEUE_NONE).build();
    }
    @Bean("ackExchangeNone")
    public DirectExchange ackExchangeNone() {
        return ExchangeBuilder.directExchange(Constants.AKC_EXCHANGE_NONE).durable(true).build();
    }
    @Bean("ackBindingNone")
    public Binding ackBinding(@Qualifier("ackQueueNone") Queue ackQueue, @Qualifier("ackExchangeNone") DirectExchange ackExchange) {
        return BindingBuilder.bind(ackQueue).to(ackExchange).with("abc");
    }

    @Bean("ackQueueManual")
    public Queue ackQueueNonManual() {
        return QueueBuilder.durable(Constants.AKC_QUEUE_MANUAL).build();
    }
    @Bean("ackExchangeManual")
    public DirectExchange ackExchangeManual() {
        return ExchangeBuilder.directExchange(Constants.AKC_EXCHANGE_MANUAL).durable(true).build();
    }
    @Bean("ackBinding")
    public Binding ackBindingManual(@Qualifier("ackQueueManual") Queue ackQueue, @Qualifier("ackExchangeManual") DirectExchange ackExchange) {
        return BindingBuilder.bind(ackQueue).to(ackExchange).with("abc");
    }

    @Bean("confirmQueue")
    public Queue confirmQueue() {
        return QueueBuilder.durable(Constants.CONFIRM_QUEUE).build();
    }
    @Bean("directExchange")
    public DirectExchange getAckExchange() {
        return ExchangeBuilder.directExchange(Constants.DIRECT_EXCHANGE).durable(true).build();
    }

    @Bean("confirmBinding")
    public Binding confirmBinding(@Qualifier("confirmQueue") Queue confirmQueue, @Qualifier("directExchange") DirectExchange directExchange) {
        return BindingBuilder.bind(confirmQueue).to(directExchange).with("abc");
    }

    @Bean("retryQueue")
    public Queue retryQueue() {
        return QueueBuilder.durable(Constants.RETRY_QUEUE).build();
    }
    @Bean("retryExchange")
    public DirectExchange retryExchange() {
        return ExchangeBuilder.directExchange(Constants.RETRY_EXCHANGE).durable(true).build();
    }
    @Bean("retryBinding")
    public Binding retryBinding(@Qualifier("retryQueue") Queue ackQueue, @Qualifier("retryExchange") DirectExchange ackExchange) {
        return BindingBuilder.bind(ackQueue).to(ackExchange).with("abc");
    }

    @Bean("ttlQueue1")
    public Queue ttlQueue1(){
        return QueueBuilder.durable(Constants.TTL_QUEUE).build();
    }
    @Bean("ttlQueue2")
    public Queue ttlQueue2(){
        return QueueBuilder.durable(Constants.TTL_QUEUE2).ttl(100000).build();
    }
    @Bean("ttlExchange")
    public DirectExchange ttlExchange(){
        return ExchangeBuilder.directExchange(Constants.TTL_EXCHANGE).durable(true).build();
    }
    @Bean("ttlBinding1")
    public Binding ttlBinding1(@Qualifier("ttlQueue1") Queue ttlQueue, @Qualifier("ttlExchange") DirectExchange ttlExchange) {
        return BindingBuilder.bind(ttlQueue).to(ttlExchange).with("ttl");
    }
    @Bean("ttlBinding2")
    public Binding ttlBinding2(@Qualifier("ttlQueue2") Queue ttlQueue, @Qualifier("ttlExchange") DirectExchange ttlExchange) {
        return BindingBuilder.bind(ttlQueue).to(ttlExchange).with("ttl");
    }

    @Bean("testQueue")
    public Queue testQueue(){
        return QueueBuilder.durable(Constants.TEST_QUEUE).build();
    }
    @Bean("testExchange")
    public DirectExchange testExchange(){
        return ExchangeBuilder.directExchange(Constants.TEST_EXCHANGE).build();
    }
    @Bean("testBinding")
    public Binding testBinding(@Qualifier("testQueue") Queue testQueue, @Qualifier("testExchange") DirectExchange testExchange){
        return BindingBuilder.bind(testQueue).to(testExchange).with("abc");
    }
}
